<?php
date_default_timezone_set('Asia/Bangkok');

class QueryExecutor{
    public $connection; 
public function QueryExecutor(){
    $this->Connection();
}    
public function Connection(){
    $conn = mysqli_connect(ConnectionProperty::getHost(), ConnectionProperty::getUser(), ConnectionProperty::getPassword(),ConnectionProperty::getDatabase());
    if(!$conn){throw new Exception('could not connect to database');}
    $conn->set_charset("utf8");
    $this->connection = $conn;
}
public function close(){
    mysqli_close($this->connection);
}
private function executeQuery($sql){
    return mysqli_query($this->connection,$sql);
}
public  function execute($sqlQuery){
    $result =  $this->executeQuery($sqlQuery);
    if(!$result){throw new Exception("SQL Error: -->".$sqlQuery."<--" . mysql_error());}
    $i=0;
    $tab = array();
    while ($row = mysqli_fetch_array($result)){ $tab[$i++] = $row; }
    mysqli_free_result($result);
    return $tab;
}	
public  function executeUpdate($sqlQuery){
    $result =  $this->executeQuery($sqlQuery);
    if(!$result){throw new Exception("SQL Error: -->".$sqlQuery."<--" . mysql_error());}
    return TRUE;		
}
public  function executeInsert($sqlQuery){
    QueryExecutor::executeUpdate($sqlQuery);
    return mysql_insert_id();
}
public  function queryForString($sqlQuery){
    $result =  $this->executeQuery($sqlQuery);
    if(!$result){throw new Exception("SQL Error: -->".$sqlQuery."<--" . mysql_error());}
    $row = mysqli_fetch_array($result);		
    return $row[0];
}
}
?>